package com.isunland.managesystem.common;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
import cn.jpush.android.api.JPushInterface;
import com.bugtags.library.Bugtags;
import com.bugtags.library.BugtagsOptions;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.utils.LogUtil;
import com.isunland.managesystem.utils.MyUtils;
import com.isunland.managesystem.utils.SharedPreferencesUtil;
import com.orhanobut.logger.Logger;

public class MyApplication extends Application {
  @SuppressWarnings("unused") private static final String TAG = "MyApplication";
  @SuppressWarnings("all") private static Context context;

  public static Context getAppContext() {
    return MyApplication.context;
  }

  @Override public void onCreate() {
    super.onCreate();
    MyApplication.context = getApplicationContext();
    // host地址
    ApiConst.getHostFromSharedPre(getApplicationContext());
    // 用户对象
    CurrentUser.newInstance(this);
    // 奥新验证
    RequestManager.init(this);
    Logger.init().methodCount(0).hideThreadInfo();
    LogUtil.allowLog(MyUtils.isLog(this));
    JPushInterface.init(MyApplication.getAppContext());
    if (MyUtils.isBugTags(this)) {
      initBugtags();
    }
  }

  private void initBugtags() {
    BugtagsOptions options = new BugtagsOptions.Builder().trackingLocation(true).// 是否获取位置
        trackingCrashLog(true).// 是否收集crash
        trackingConsoleLog(true).// 是否收集console log
        trackingUserSteps(true).// 是否收集用户操作步骤
        build();
    // 启动崩溃日志收集,debug时关掉,因为报错太多太乱.正式版本时打开.
    // 同时打开BaseVolleyActivity中的三个回调.
    int type = SharedPreferencesUtil.getInt(this, SharedPreferencesUtil.BUGTAGS_OPTIONS, 0);
    Bugtags.start("d86ecbf48beeb731b7cc63f3a7a78b5a", this, type, options);
  }

  @Override protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
  }
}
